package miao.byusi.bkata.logs.config

import miao.byusi.bkata.logs.Color
import miao.byusi.bkata.logs.LogLevel
import miao.byusi.bkata.logs.Style

data class StyleConfig(
    val color: String? = null,
    val bgColor: String? = null,
    val bold: Boolean? = null,
    val italic: Boolean? = null,
    val underline: Boolean? = null
) {
    fun toStyle(): Style {
        return Style(
            color = color?.let { Color.fromString(it) },
            bgColor = bgColor?.let { Color.fromString(it) },
            bold = bold ?: false,
            italic = italic ?: false,
            underline = underline ?: false
        )
    }
}

data class ThemeConfig(
    val styles: Map<String, StyleConfig> = emptyMap()
) {
    fun toTheme(): miao.byusi.bkata.logs.Theme {
        val theme = miao.byusi.bkata.logs.Theme()
        styles.forEach { (level, styleConfig) ->
            LogLevel.fromString(level)?.let { logLevel ->
                theme.setStyle(logLevel, styleConfig.toStyle())
            }
        }
        return theme
    }
}

data class LoggerConfig(
    val name: String = "Bkata",
    val minLevel: String = "INFO",
    val showTime: Boolean = true,
    val showName: Boolean = true,
    val theme: ThemeConfig = ThemeConfig()
)

data class BkataConfig(
    val defaultLogger: LoggerConfig = LoggerConfig()
)